/**
 * 项目名称：MSH
 * 包名称：com.mt.common.log.serviceImpl
 * 文件名称：LogServiceImpl.java
 */
package com.mt.system.serviceImpl;

import java.util.Date;
import java.util.List;

import javax.annotation.Resource;

import org.springframework.flex.remoting.RemotingDestination;
import org.springframework.flex.remoting.RemotingInclude;
import org.springframework.stereotype.Service;

import com.mt.system.dao.LoginLogDao;
import com.mt.system.dao.OptLogDao;
import com.mt.system.dao.PermissionDao;
import com.mt.system.domain.LoginLog;
import com.mt.system.domain.OptLog;
import com.mt.system.dto.LogDto;
import com.mt.system.service.LogService;
import com.mt.utils.IPUtils;


/**
 * 类名称：LogServiceImpl <br>
 * 类描述：日志service <br>
 * 创建人： 马腾 <br>
 * 创建时间：Oct 25, 2012 10:33:10 AM <br>
 */
@Service("LogService")
@RemotingDestination(channels = {"my-amf"})
public class LogServiceImpl implements LogService {
	
	@Resource
	private LoginLogDao loginLogDao;
	@Resource
	private PermissionDao permissionDao;
	@Resource
	private OptLogDao optLogDao;

	@RemotingInclude
	@Override
	public LoginLog addLoginLog(LoginLog loginLog) {
		loginLog.setLoginIp(IPUtils.getClientIp());
		loginLog.setLoginTime(new Date());
		return loginLogDao.addLoginLog(loginLog);
	}

	@RemotingInclude
	@Override
	public void addOptLog(OptLog optLog) {
		optLog.setOptIp(IPUtils.getClientIp());
		optLog.setOptTime(new Date());
		optLog.setPermission(permissionDao.getPermissionByMark(optLog.getPermission().getMark()));
		optLogDao.addOptLog(optLog);
	}

	@RemotingInclude
	@Override
	public List<LoginLog> getLoginLogs(LogDto logDto, int first, int max) {
		return loginLogDao.getLoginLogs(logDto, first, max);
	}

	@RemotingInclude
	@Override
	public int getLoginLogCount(LogDto logDto) {
		return loginLogDao.getLoginLogCount(logDto);
	}

	@RemotingInclude
	@Override
	public List<OptLog> getOptLogs(LogDto logDto, int first, int max) {
		return optLogDao.getOptLogs(logDto, first, max);
	}

	@RemotingInclude
	@Override
	public int getOptLogCount(LogDto logDto) {
		return optLogDao.getOptLogCount(logDto);
	}
	
}
